package org.csu.mypetstore.api.controller.frontend;

import org.csu.mypetstore.api.common.CommonResponse;
import org.csu.mypetstore.api.entity.Account;
import org.csu.mypetstore.api.service.AccountService;
import org.csu.mypetstore.api.vo.AccountVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Repository;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.security.NoSuchAlgorithmException;
import java.util.List;

@Controller
@RequestMapping("/account")
public class AccountController {
    @Autowired
    private AccountService accountService;

    @GetMapping("accounts")
    @ResponseBody
    public CommonResponse<List<AccountVO>> getAllAccount() {
        return accountService.getAllAccountList();
    }

    @GetMapping("existence/{username}")
    @ResponseBody
    public CommonResponse<Account> getAccountByUsername( @PathVariable("username") String username ){
        return accountService.getAccount( username );
    }

    @GetMapping("vo/{username}/{psw}")
    @ResponseBody
    public CommonResponse<AccountVO> getAccountVO(@PathVariable("username") String username, @PathVariable("psw") String password) throws NoSuchAlgorithmException {
        return accountService.getAccount( username, password );
    }

}
